package com.wzapp.sitposture;

import com.wzapp.sitposture.config.H5Properties;
import com.wzapp.sitposture.eshop.endpoint.AliNotifyServlet;
import com.wzapp.sitposture.eshop.endpoint.WeixinNotifyServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication
@EnableConfigurationProperties({ H5Properties.class})
@EnableAsync
@EnableTransactionManagement
@EnableCaching //启用缓存配置
@EnableScheduling
public class Application extends SpringBootServletInitializer{

    private static final Logger logger = LoggerFactory.getLogger(Application.class);

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(Application.class);
    }

    public static void main(String []args){
        long star = System.currentTimeMillis();
        SpringApplication.run(Application.class , args);
        logTest();
        long end = System.currentTimeMillis();

        logger.info("-----------------耗时：" + (end - star)/1000 + " 秒");
    }

    public static void logTest() {
        logger.debug("----------------------------日志输出测试 Debug");
        logger.trace("----------------------------日志输出测试 Trace");
        logger.info("----------------------------日志输出测试 Info");
        logger.error("----------------------------日志输出测试 Error");
    }
    /**
     * 使用代码注册Servlet（不需要@ServletComponentScan注解）
     *
     */
    @Bean
    public ServletRegistrationBean servletRegistrationBean() {
        return new ServletRegistrationBean(new WeixinNotifyServlet(), "/notify/servernotify_wx");// ServletName默认值为首字母小写，即myServlet
    }

    @Bean
    public ServletRegistrationBean aliServletRegistrationBean() {
        return new ServletRegistrationBean(new AliNotifyServlet(), "/notify/servernotify_ali");// ServletName默认值为首字母小写，即myServlet
    }
}
